package com.tz.fdz_jiance.controller;

import com.tz.fdz_jiance.domain.Admin;
import com.tz.fdz_jiance.mapper.AdminMapper;
import com.tz.fdz_jiance.utils.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;

@RestController
public class LoginController {

    //自动注入的查询器，数据库每个表一个，用mybatis generator生成的（generatorConfig。xml中的table表名，
    //然后去mavenprojects的plugins的mybatis-generator运行）

    @Autowired
    AdminMapper adminMapper;

    @PostMapping("/login")
    @CrossOrigin(origins = "*",maxAge = 3600)
    public HashMap<String, Object> login(@RequestBody Admin admin, HttpServletRequest request, HttpSession session) {
        Admin realadmin = adminMapper.selectById(1);



        if (admin.getName().equals(realadmin.getName()) && admin.getPass().equals(realadmin.getPass())) {

            return ResponseUtils.success("login success");
        }
        return ResponseUtils.fail("login fail");
    }

}